const App = {
  mixins: [Query], //配置文件，路径/utils/mixins.js
  data() {
    return {
      statistics: {
        "A类人员": { total: 0 },
        "B类人员": { total: 0 },
        "C类人员": { total: 0 },
        "D类人员": { total: 0 },
      },
      teeed: "",
      party_fees: {
        Party_Fee_SerialNumber: "", //党费缴纳流水号
        Party_Member_SerialNumber: "", //党员流水号
        Party_Organization_SerialNumber: "", //所属党组织编号
        Fee_Date: "", //党费日期
        Fee_Amount: "", //党费金额
      },
      totalMembers: 111, //总人数
      fullMembers: 11, //正式党员
      probationaryMembers: 1, //预备党员
      input: "", //输入框
      value2: getYMDate(),
      options: [],
      treeData: [], //树的数据
      originalTreeData: [], //原始树的数据
      originalTableData: [], // 原始表格的数据
      columns: [], //表格的列
      loading: false, //表数据的懒加载
      showDialog: false, //设置字段弹窗
      checkedFields: [], //选中的字段
      isDataReady: false,
      Tabletdata: [], //表格的数据
      fields: [], //字段列表
      // showaddDialog: false, //添加字段弹窗
      value: "",
      page: {
        activeName: 'first',
        value1: "",
        value2: "",
        value3: "",
        PageNumber: 1, //页码
        RowAmount: 10,
        Condition: window.btoa(unescape(encodeURIComponent("%%,%%,%%"))),
        ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND personal_information.RR_Village_Number IN (" + getCookie('village') + ")\r\n"))),
      },
      str1: '',
      str2: '',
      str3:"AND personal_information.RR_Village_Number IN (" + getCookie('village') + ")\r\n",
      calendar: false,
      Party_Organization_SerialNumber: "",
      organization: [],
      isbatch: false,
      Focus: '',
    };
  },
  mounted() {
    this.Treedata();
    this.ctj();
  },
  methods: {
    handlebatchbj() {
      this.isbatch = true;
      this.Focus = '0';
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
    },
    handlebatchqxbj() {
      this.isbatch = true;
      this.Focus = '1';
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
    },
    handlebatchqx() {
      this.isbatch = false;
      this.Focus = '';
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
    },
    handlebatchtj() {
      if (this.multipleSelection.length > 0) {
        this.loading = true;
        let str = this.multipleSelection.map(i => "'" + i.ID_Card_Number + "'").join(",");
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
          method: "post",
          data: {
            Data: 'personal_information',
            Condition: `ID_Card_Number IN (${str})`,
          },
          success: (data) => {
            data.forEach(item => {
              item.Focus = (this.Focus == '0' ? '1' : '0')
            })
            let lJSONObject_DataSet = {
              Modify: {
                personal_information:data
              },
              Add: {}
            }
            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
            lJSONObject_DataSet['Add']['base_operation_log'] = [{
              Operation_Type: '0',
              Operation_Path: this.relativePath,
              Operation_Main,
              Operation_Interface: "generalSave",
              Operation_IP: getIpAddress()
            }]
            submitSave(lJSONObject_DataSet, (res) => {
              if (res.Status == 'success') {
                this.handlebatchqx()
                this.postgetList(this.page);
              } else {
                this.$message({
                  type: 'error',
                  message: '操作失败'
                });
                this.loading = false;
              }
            })
          },
          complete: (XMLHttpRequest) => {
            requestPretreatment(XMLHttpRequest)
          },
        });
      } else {
        this.$message({
          type: 'warning',
          message: '请选择要修改的数据'
        });
      }
    },
    selectable(row) {
      return row.Focus == this.Focus;
    },
    handleClick() {
      if (this.page.activeName == 'first') {
        this.str2 = '';

      } else if (this.page.activeName == 'second') {
        this.str2 = "AND personal_information.Focus='1'\r\n"
      }
      this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str1 + this.str2 + this.str3)));
      this.postgetList(this.page);
    },
    ctj() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/population/keyPersonStatistics`,
        type: "GET",
        data: {
          Village_SerialNumber:getCookie('village'), //请求参数
        },
        success: function (data) {
          for (const key in _this.statistics) {
            if (data[key] !== undefined) {
              _this.statistics[key].total = data[key];
            }
          }
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableName`,
        method: "post",
        data: {
          Data: 'personal_tags',
          Condition: `Row_Status='0'`,
        },
        success: (res) => {
          this.options = res
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest)
        },
      });
    },
    //树的数据
    Treedata() {
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/permissionsTree/getDistrictTreeByPermissions`,
        type: "GET",
        data: {
          DistrictCode: getCookie('village'), //请求参数
        },
        success:  (data)=> {
          this.treeData = data;
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    personalAdd() {
      window.location.href = "./party_feesAdd.html?action=Modify";
    },
    handleEdit(row) {
      let { primary_key } = JSON.parse(
        document.getElementById("table").getAttribute("data-options")
      );
      window.location.href =
        "./party_feesAdd.html?action=Modify&nodeKey=" + row[primary_key];
    },
    check() {
      this.page.Condition = window.btoa(unescape(encodeURIComponent("%%,%" + this.page.value1 + "%,%" + this.page.value2 + "%")));
      if (this.page.value3) {
        this.str1 = `AND personal_information.ID_Card_Number IN (
          SELECT DISTINCT personal_information.ID_Card_Number
          FROM personal_information LEFT JOIN personal_mapping_tags
          ON personal_information.ID_Card_Number = personal_mapping_tags.ID_Card_Number
          WHERE personal_mapping_tags.Personal_Tag_SerialNumber = '${this.page.value3}'
          AND personal_mapping_tags.Row_Status = '0')`
         
      } else {
        this.str1 = '';
      }
      this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(this.str1 + this.str2 + this.str3)));
      this.postgetList(this.page);
    },
    handleNodeClick(data) {
      this.page.Condition = window.btoa(
        unescape(
          encodeURIComponent(
            "%" +
            data.ProvinceNumber +
            "%,%" +
            this.page.value1 +
            "%,%" +
            this.page.value2 +
            "%"
          )
        )
      );
      this.postgetList(this.page);
    },
    handlebj(row) {
      this.$confirm('是否' + (row.Focus == '0' ? '重点关注' : '取消关注') + '该人员', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
          method: "post",
          data: {
            Data: TableName,
            Condition: primary_key + "='" + row[primary_key] + "'"
          },
          success: (res) => {
            if (res.length == 1) {
              res[0].Focus = (row.Focus == '0' ? '1' : '0');
              let lJSONObject_DataSet = new Object();
              let lJSONObject_Table = new Object();
              lJSONObject_Table[TableName] = res;
              lJSONObject_DataSet['Modify'] = lJSONObject_Table;
              let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
              if (!lJSONObject_DataSet['Add']) {
                lJSONObject_DataSet['Add'] = new Object();
              }
              lJSONObject_DataSet['Add']['base_operation_log'] = [{
                Operation_Type: '0',
                Operation_Path: this.relativePath,
                Operation_Main,
                Operation_Interface: "generalSave",
                Operation_IP: getIpAddress()
              }]
              submitSave(lJSONObject_DataSet, (res) => {
                if (res.Status == 'success') {
                  this.postgetList(this.page);
                } else {
                  this.$message({
                    type: 'error',
                    message: '操作失败'
                  });
                }
              })
              // $.ajax({
              //   headers: requestHeaders(),
              //   url: `${mh}/generalBusiness/generalSave`,
              //   method: "post",
              //   data: {
              //     Data: JSON.stringify(lJSONObject_DataSet),
              //   },
              //   success: (res) => {
              //     if (res.Status == 'success') {
              //       this.postgetList(this.page);
              //     } else {
              //       this.$message({
              //         type: 'error',
              //         message: '操作失败'
              //       });
              //     }
              //   },
              //   complete: (XMLHttpRequest) => {

              //     requestPretreatment(XMLHttpRequest);
              //   }
              // });
            } else {
              this.$message({
                type: 'error',
                message: '操作失败'
              });
            }

          }, complete: (XMLHttpRequest) => {

            requestPretreatment(XMLHttpRequest);
          }
        });
      }).catch(() => { });
    }
  },
};
const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.component("yl-monthly-calendar", ylMonthlyCalendar);
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
